package functions;

import com.beans.TaskBean;
import com.crc.mam.BaseCase;
import coms.AutoException;
import coms.Constants;
import coms.process.LoginTest;
import frame.FrameWork;
import frame.HttpHelper;
import frame.InterTest;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyHistoryTask extends BaseCase implements InterTest
{
	private static Logger logger = LoggerFactory.getLogger(MyHistoryTask.class);
	private String claimNo;
	private String getRemark;
	private String startapplyDate;
	private String endapplyDate;
	private String ouCode;
	private String submitter;
	private String vendorCode;
	private String result;
	TaskBean taskBean;

	public String getClaimNo()
	{
		return this.claimNo;
	}

	public void setClaimNo(String claimNo) {
		this.claimNo = claimNo;
	}

	public String getGetRemark() {
		return this.getRemark;
	}

	public void setGetRemark(String getRemark) {
		this.getRemark = getRemark;
	}

	public String getStartapplyDate() {
		return this.startapplyDate;
	}

	public void setStartapplyDate(String startapplyDate) {
		this.startapplyDate = startapplyDate;
	}

	public String getEndapplyDate() {
		return this.endapplyDate;
	}

	public void setEndapplyDate(String endapplyDate) {
		this.endapplyDate = endapplyDate;
	}

	public String getOuCode() {
		return this.ouCode;
	}

	public void setOuCode(String ouCode) {
		this.ouCode = ouCode;
	}

	public String getSubmitter() {
		return this.submitter;
	}

	public void setSubmitter(String submitter) {
		this.submitter = submitter;
	}

	public String getVendorCode() {
		return this.vendorCode;
	}

	public void setVendorCode(String vendorCode) {
		this.vendorCode = vendorCode;
	}

	public String getResult() {
		return this.result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public TaskBean getTaskBean() {
		return this.taskBean;
	}

	public void setTaskBean(TaskBean taskBean) {
		this.taskBean = taskBean;
	}

	public MyHistoryTask()
	{
	}

	public MyHistoryTask(String claimNo, String getRemark, String startapplyDate, String endapplyDate, String ouCode, String submitter, String vendorCode, String result) {
		this.claimNo = claimNo;
		this.getRemark = getRemark;
		this.startapplyDate = startapplyDate;
		this.endapplyDate = endapplyDate;
		this.ouCode = ouCode;
		this.submitter = submitter;
		this.vendorCode = vendorCode;
		this.result = result;
	}

	public void myProcessed(String claimNo) {
		logger.info("通过报账单号：" + claimNo + "查询我的已审批------start-----");
		String url = Constants.MY_HISTORY_TASK_URL;

		String params = "{\"page\":{\"currentPage\":1,\"pageSize\":10,\"recordCount\":1},\"params\":{\"catalogyCodeList\":[],\"claimAountlest\":\"\",\"claimAountmost\":\"\",\"startapplyDate\":\"\",\"endapplyDate\":\"\",\"accountingPeriod\":\"\",\"result\":[{\"claimNo\":\"" + 
				claimNo + "\",\"getRemark\":\"\",\"ouCode\":\"\",\"submitter\":\"\",\"venderCode\":\"\",\"venderName\":\"\"}]}," + 
				"\"sortDTO\":{\"fieldName\":\"\",\"orderBy\":\"\"}}";
		try
		{
			this.result = HttpHelper.post(params, url);
			this.status = HttpHelper.isOk;
			logger.info("findMyHistoryTask--------" + this.result);
			if (this.status) {
				try {
					JSONObject object = new JSONObject(this.result);
					int t = object.getInt("total");
					if (t == 1) {
						JSONArray array = object.getJSONArray("list");
						JSONObject datas = array.getJSONObject(0);
						logger.info(datas.toString());
					}this.status = false;
					this.remark = ("没有找到需要审批的报账单 " + claimNo);
				}catch (JSONException e){
					e.printStackTrace();
					this.status = false;
					this.remark = "JSON解析错误";
				}
			}else {
				try {
					JSONObject object = new JSONObject(this.result);
					this.remark = object.getString("message");
				} catch (JSONException e) {
					e.printStackTrace();
					this.remark = "JSON解析错误";
				}
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			this.status = false;
			this.remark = "系统异常";
		}
		logger.info("通过报账单号：" + claimNo + "查询我的已审批------end-----");
	}

	public void run(Map<Object, Object> paramMap)
	{
		String baseUrl = (String)paramMap.get("baseUrl");
		if (baseUrl != null) {
			FrameWork.setBaseUrl(baseUrl);
		}
		LoginTest loginTest = new LoginTest();
		loginTest.run(paramMap);
		if (!loginTest.status) {
			this.remark = loginTest.result;
			this.status = false;
			throw new AutoException("登录失败: " + this.remark + "，阻碍测试");
		}

		String claimNo = (String)paramMap.get("claimNo");
		myProcessed(claimNo);
	}

	public boolean getStatus()
	{
		return false;
	}
}